//
//  TitleButton.swift
//  DSWeiBo
//
//  Created by Frank Wang on 7/7/16.
//  Copyright © 2016 Frank Wang. All rights reserved.
//

import UIKit

class TitleButton: UIButton {
        
        
        override init(frame: CGRect) {
             super.init(frame: frame)
                setTitleColor(UIColor.darkGrayColor(), forState: UIControlState.Normal)
                setImage(UIImage(named: "navigationbar_arrow_down"), forState: UIControlState.Normal)
                setImage(UIImage(named: "navigationbar_arrow_up"), forState: UIControlState.Selected)
                sizeToFit()
        }
        
        required init?(coder aDecoder: NSCoder) {
               fatalError("init(coder) has not been implement")
        }
        
        //布局子控件
        override func layoutSubviews() {
                super.layoutSubviews()
                //swift中可以修改结构体的参数
                titleLabel?.frame.origin.x = 0
                imageView?.frame.origin.x = titleLabel!.frame.size.width
                
                
                /*
                titleLabel?.frame.offsetInPlace(dx: -imageView!.bounds.width * 0.5, dy: 0)
                imageView?.frame.offsetInPlace(dx: titleLabel!.bounds.width * 0.5, dy: 0)
                */
        }
}
